package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.wf.bi.web.form.WfTemplateAttachmentRefForm;
import com.augurit.wf.common.entity.WfTemplateAttachmentRef;

public class WfTemplateAttachmentRefConvertor {
	public static WfTemplateAttachmentRef convertFormToVo(WfTemplateAttachmentRefForm form, WfTemplateAttachmentRef entity){
		if(form != null){
			if(form.getId() != null)
				entity.setId(form.getId());
			if(form.getTemplateId() != null)
				entity.setTemplateId(form.getTemplateId());
			if(form.getFileCode() != null && form.getFileCode().trim().length() > 0)
				entity.setFileCode(form.getFileCode());
			if(form.getFilePath() != null && form.getFilePath().trim().length() > 0)
				entity.setFilePath(form.getFilePath());
			if(form.getFileName() != null && form.getFileName().trim().length() > 0)
				entity.setFileName(form.getFileName());
			if(form.getFileType() != null && form.getFileType().trim().length() > 0)
				entity.setFileType(form.getFileType());
			if(form.getCreator() != null && form.getCreator().trim().length() > 0)
				entity.setCreator(form.getCreator());
			if(form.getCreateTime() != null)entity.setCreateTime(form.getCreateTime());
			if(form.getUpdator() != null && form.getUpdator().trim().length() > 0)
				entity.setUpdator(form.getUpdator());
			if(form.getUpdateTime() != null)
				entity.setUpdateTime(form.getUpdateTime());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo());
			
			if(form.getFileFormat() != null && form.getFileFormat().trim().length() > 0){
				entity.setFileFormat(form.getFileFormat());
			}
		}
		return entity;
	}
	
	public static WfTemplateAttachmentRefForm convertVoToForm(WfTemplateAttachmentRef entity){
		WfTemplateAttachmentRefForm form = new WfTemplateAttachmentRefForm();
		
		if(entity != null){
			form = new WfTemplateAttachmentRefForm();
			form.setId(entity.getId());
			form.setTemplateId(entity.getTemplateId());
			form.setFileCode(entity.getFileCode());
			form.setFilePath(entity.getFilePath());
			form.setFileName(entity.getFileName());
			form.setCreator(entity.getCreator());
			form.setCreateTime(entity.getCreateTime());
			form.setUpdator(entity.getUpdator());
			form.setUpdateTime(entity.getUpdateTime());
			form.setMemo(entity.getMemo());
			form.setFileFormat(entity.getFileFormat());
			form.setFileType(entity.getFileType());
		}
		return form;
	}
	
	public static List<WfTemplateAttachmentRefForm> convertToFormList(List<WfTemplateAttachmentRef> entities){
		List<WfTemplateAttachmentRefForm> results = null;
		if(entities != null && entities.size() > 0){
			results = new ArrayList<WfTemplateAttachmentRefForm>();
			for(int i = 0; i < entities.size(); i++){
				results.add(convertVoToForm(entities.get(i)));
			}
		}
		return results;
	}
	
	public static List<WfTemplateAttachmentRefForm> convertObjsToFormList(List<Object[]> objs){
		List<WfTemplateAttachmentRefForm> results = null;
		if(objs != null && objs.size() > 0){
			results = new ArrayList<WfTemplateAttachmentRefForm>();
			for(Object[] obj:objs){
				WfTemplateAttachmentRef entity = (WfTemplateAttachmentRef)obj[0];
				String templateCode = (String)obj[1];
				
				WfTemplateAttachmentRefForm form = convertVoToForm(entity);
				form.setTemplateCode(templateCode);
				results.add(form);
			}
		}
		return results;
	}
}
